package com.cl.pattern.memento.ext;

/**
 * @ClassName Originator
 * @Description 发起人角色
 * @Author Small
 * @Date 2020/7/9 10:19
 * @Version 1.0
 **/
public class Originator {
    /**
     * 内部状态
     */
    private String state = "";

    /**
     * 创建备忘录
     *
     * @return
     */
    public Memento createMemento() {
        return new Memento(this.state);
    }

    /**
     * 恢复备忘录
     *
     * @param memento
     */
    public void restoreMemento(Memento memento) {
        this.setState(memento.getState());
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }


    private class Memento implements  IMemento{
        /**
         * 发起人内部状态
         */
        private String state = "";

        public Memento(String state) {
            this.state = state;
        }

        public String getState() {
            return state;
        }

        public void setState(String state) {
            this.state = state;
        }
    }
}
